Skip to content

fix: decode empty jsonrpc methods as requests#983

Closed
he-yufeng wants to merge 1 commit into
modelcontextprotocol:mainfrom
he-yufeng:fix/respond-empty-method
Closed

fix: decode empty jsonrpc methods as requests#983
he-yufeng wants to merge 1 commit into
modelcontextprotocol:mainfrom
he-yufeng:fix/respond-empty-method

Conversation

@he-yufeng
Copy link
Copy Markdown
Contributor

Fixes #976.

An incoming JSON-RPC message with an explicit empty method field was decoded as a response because the wire struct could not distinguish a missing method from an empty method. That meant stdio servers silently ignored requests like id=5/method="" instead of routing them through request handling and returning a correlated JSON-RPC error.

This keeps method presence during decode by storing the wire method as a pointer, then decodes method="" as a Request. The existing dispatch path can then return method-not-found for the request id while leaving the session alive.

Validation:

  • go test ./internal/jsonrpc2
  • go test ./mcp -run "TestIOConnRead|TestServerSessionHandle|TestKeepAliveMethodNotFound"
  • go test ./...

@he-yufeng
Copy link
Copy Markdown
Contributor Author

Closing this duplicate version in favor of #980, which is up to date and green for the same #976 fix. Keeping one active PR should make review clearer.

@he-yufeng he-yufeng closed this Jun 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Stdio server leaves some malformed JSON-RPC requests unanswered while the session remains alive

1 participant